package com.digitalchina.lxnsy.xml;

import android.content.Context;

import com.digitalchina.lxnsy.entity.ExpertInfoVO;
import com.digitalchina.lxnsy.toolkit.SharedPreferencesUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.xml
 * 创建人：郑皓
 * 创建时间：2017/7/20 20:01
 * 修改备注：
 * ================================================
 */
public class ExpertInfoXML {
    public static final String XML_NAME_EXPERT_INFO = "ExpertInfo";

    private static final String ID = "id";
    private static final String PHOTO = "photo"; // 头像
    private static final String EXPERTSEX = "expertSex"; // 性别
    private static final String WORKUNIT = "workUnit"; // 工作单位
    private static final String ADDRESS = "address"; // 工作地址 <省市区name> 用作展示
    private static final String ADDRESSDETAIL = "addressDetail";  // 详细地址
    private static final String ACHIEVEMENT = "achievement"; // 个人成就
    private static final String EXPERTINTRODUCE = "expertIntroduce"; // 个人简介
    private static final String EXPERTCLASSIFICATION = "expertClassification"; // 专业分类name <用作展示>
    private static final String EXPERTAREATYPECODE = "expertAreaType"; // 三级分类code集合
    private static final String EXPERTAREADIRECTIONCODE = "expertAreaDirection"; // 专业领域code集合


    private static final String PROVINCECODE = "provinceCode";   // 省编码
    private static final String CITYCODE = "cityCode";   // 市编码
    private static final String COUNTYCODE = "countyCode";   // 区编码


    private static final String ISAUDIT = "isAudit";   // 第一次审核
    private static final String ISCHANGEAUDIT = "isChangeAudit";   // 修改后审核

    private static final String ORGANIZATION_ID = "organization_ID";
    private static final String ORGANIZATION_NAME = "organization_name";
    private static final String OTHERADDRESS = "otherAddress";

    private static final String BIRTHDAY = "birthday"; // 生日


    /**
     * ---------------认证信息-------------------
     */
    private static final String EXPERTNAME = "expertName";   // 真实姓名
    private static final String EXPERTTITLENAME = "expertTitleName";   // 专家职称name
    private static final String EXPERTTITLECODE = "expertTitleCode";   // 专家职称code
    private static final String EXPERTTITLENUM = "expertTitleNum";   // 专家职称号
    private static final String EXPERTTITLEIMAGE = "expertTitleImage";   // 专家职称照片
    private static final String IDCARDNUM = "idCardNum";   // 身份证号
    private static final String IDCARDIMAGE = "idCardImage";   // 身份证照片


    public static void setExpertInfoVO(Context ctx, ExpertInfoVO expertInfoVO) {
        setValue(ctx, ID, expertInfoVO.getId());
        setValue(ctx, PHOTO, expertInfoVO.getPhoto());
        setValue(ctx, EXPERTSEX, expertInfoVO.getExpertSex());
        setValue(ctx, WORKUNIT, expertInfoVO.getWorkUnit());
        setValue(ctx, ADDRESSDETAIL, expertInfoVO.getAddressDetail());
        setValue(ctx, ACHIEVEMENT, expertInfoVO.getAchievement());
        setValue(ctx, EXPERTINTRODUCE, expertInfoVO.getExpertIntroduce());
        if (!StringUtil.isStrEmpty(expertInfoVO.getBirthday()))
            setValue(ctx, BIRTHDAY, expertInfoVO.getBirthday());
        if (expertInfoVO.getExpertClassification() != null && !StringUtil.isStrEmpty(expertInfoVO.getExpertClassification().getPname()))
            setValue(ctx, EXPERTCLASSIFICATION, expertInfoVO.getExpertClassification().getPname() + "  " + expertInfoVO.getExpertClassification().getName());

        if (expertInfoVO.getExpertAreas() != null) {
            String expertAreaType = "";
            String expertAreaDirection = "";
            for (int i = 0; i < expertInfoVO.getExpertAreas().size(); i++) {
                expertAreaType += expertInfoVO.getExpertAreas().get(i).getExpertAreaType().getRcode() + ",";
                expertAreaDirection += expertInfoVO.getExpertAreas().get(i).getExpertAreaDirection().getCode() + ",";
            }
            if (expertAreaType.length() > 0)
                setValue(ctx, EXPERTAREATYPECODE, expertAreaType.substring(0, expertAreaType.length() - 1));
            if (expertAreaDirection.length() > 0)
                setValue(ctx, EXPERTAREADIRECTIONCODE, expertAreaDirection.substring(0, expertAreaDirection.length() - 1));
        }


        setValue(ctx, EXPERTNAME, expertInfoVO.getExpertName());
        if (expertInfoVO.getExpertTitle() != null) {
            if (!StringUtil.isStrEmpty(expertInfoVO.getExpertTitle().getTitle()))
                setValue(ctx, EXPERTTITLENAME, expertInfoVO.getExpertTitle().getTitle());
            if (!StringUtil.isStrEmpty(expertInfoVO.getExpertTitle().getId()))
                setValue(ctx, EXPERTTITLECODE, expertInfoVO.getExpertTitle().getId());
        }

        setValue(ctx, EXPERTTITLENUM, expertInfoVO.getExpertTitleNum());
        setValue(ctx, EXPERTTITLEIMAGE, expertInfoVO.getExpertTitleImage());
        setValue(ctx, IDCARDNUM, expertInfoVO.getIdCardNum());
        setValue(ctx, IDCARDIMAGE, expertInfoVO.getIdCardImage());

        if (expertInfoVO.getOrganization() != null) {
            setValue(ctx, ORGANIZATION_ID, expertInfoVO.getOrganization().getId());
            setValue(ctx, ORGANIZATION_NAME, expertInfoVO.getOrganization().getName());
        }

        if (!StringUtil.isStrEmpty(expertInfoVO.getOtherAddress()))
            setValue(ctx, OTHERADDRESS, expertInfoVO.getOtherAddress());


        setIsAudit(ctx, expertInfoVO.getIsAudit());
        setIsChangeAudit(ctx, expertInfoVO.getIsChangeAudit());

        if (expertInfoVO.getProvince() != null && expertInfoVO.getCity() != null && expertInfoVO.getCounty() != null) {

            if (expertInfoVO.getProvince().equals("110000") || expertInfoVO.getProvince().equals("120000") || expertInfoVO.getProvince().equals("310000") || expertInfoVO.getProvince().equals("500000")
                    || (expertInfoVO.getProvince().equals("460000") && expertInfoVO.getCity().equals("469000"))) {
                setValue(ctx, ADDRESS, String.format("%s %s", expertInfoVO.getProvince().getName(), expertInfoVO.getCounty().getName()));
            } else {
                setValue(ctx, ADDRESS, String.format("%s %s %s", expertInfoVO.getProvince().getName(), expertInfoVO.getCity().getName(), expertInfoVO.getCounty().getName()));
            }
        }

        if (expertInfoVO.getProvince() != null)
            setValue(ctx, PROVINCECODE, expertInfoVO.getProvince().getCode());
        if (expertInfoVO.getCity() != null)
            setValue(ctx, CITYCODE, expertInfoVO.getCity().getCode());
        if (expertInfoVO.getCounty() != null)
            setValue(ctx, COUNTYCODE, expertInfoVO.getCounty().getCode());

    }

    private static void setValue(Context ctx, String psKey, String psValue) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, psKey, psValue);
    }

    /**
     * "photo"; // 头像
     *
     * @param ctx
     * @param value
     */
    public static void setPhoto(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, PHOTO, value);
    }

    public static String getPhoto(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, PHOTO, "");
    }

    /**
     * "expertSex"; // 性别
     *
     * @param ctx
     * @param value
     */
    public static void setExpertSex(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, EXPERTSEX, value);
    }

    public static String getExpertSex(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, EXPERTSEX, "");
    }

    /**
     * "workUnit"; // 工作单位
     *
     * @param ctx
     * @param value
     */
    public static void setWorkUnit(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, WORKUNIT, value);
    }

    public static String getWorkUnit(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, WORKUNIT, "");
    }

    /**
     * "address"; // 工作地址 <省市区name> 用作展示
     *
     * @param ctx
     * @param value
     */
    public static void setAddress(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, ADDRESS, value);
    }

    public static String getAddress(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, ADDRESS, "");
    }

    /**
     * "addressDetail";  // 详细地址
     *
     * @param ctx
     * @param value
     */
    public static void setAddressDetail(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, ADDRESSDETAIL, value);
    }

    public static String getAddressDetail(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, ADDRESSDETAIL, "");
    }

    /**
     * "achievement"; // 个人成就
     *
     * @param ctx
     * @param value
     */
    public static void setAchievement(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, ACHIEVEMENT, value);
    }

    public static String getAchievement(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, ACHIEVEMENT, "");
    }

    /**
     * "expertIntroduce"; // 个人简介
     *
     * @param ctx
     * @param value
     */
    public static void setExpertIntroduce(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, EXPERTINTRODUCE, value);
    }

    public static String getExpertIntroduce(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, EXPERTINTRODUCE, "");
    }

    /**
     * "expertClassification"; // 专业分类name <用作展示>
     *
     * @param ctx
     * @param value
     */
    public static void setExpertClassification(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, EXPERTCLASSIFICATION, value);
    }

    public static String getExpertClassification(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, EXPERTCLASSIFICATION, "");
    }

    /**
     * "expertAreaType"; // 三级分类code集合
     *
     * @param ctx
     * @param value
     */
    public static void setExpertAreaType(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, EXPERTAREATYPECODE, value);
    }

    public static String getExpertAreaType(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, EXPERTAREATYPECODE, "");
    }

    /**
     * "expertAreaDirection"; // 专业领域code集合
     *
     * @param ctx
     * @param value
     */
    public static void setExpertAreaDirection(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, EXPERTAREADIRECTIONCODE, value);
    }

    public static String getExpertAreaDirection(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, EXPERTAREADIRECTIONCODE, "");
    }


    /**
     * 设置省code
     *
     * @param ctx
     * @param value
     */
    public static void setProvinceCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, PROVINCECODE, value);
    }

    /**
     * 获取省code
     *
     * @param ctx
     * @return
     */
    public static String getProvinceCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, PROVINCECODE, "");
    }

    /**
     * 设置市code
     *
     * @param ctx
     * @param value
     */
    public static void setCityCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, CITYCODE, value);
    }

    /**
     * 获取市code
     *
     * @param ctx
     * @return
     */
    public static String getCityCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, CITYCODE, "");
    }

    /**
     * 设置区code
     *
     * @param ctx
     * @param value
     */
    public static void setCountyCodeCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, COUNTYCODE, value);
    }

    /**
     * 获取区code
     *
     * @param ctx
     * @return
     */
    public static String getCountyCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, COUNTYCODE, "");
    }

    /**
     * "expertName";   // 真实姓名
     *
     * @param ctx
     * @param value
     */
    public static void setExpertName(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, EXPERTNAME, value);
    }

    public static String getExpertName(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, EXPERTNAME, "");
    }

    /**
     * "expertTitleName";   // 专家职称name
     *
     * @param ctx
     * @param value
     */
    public static void setExpertTitleName(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, EXPERTTITLENAME, value);
    }

    public static String getExpertTitleName(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, EXPERTTITLENAME, "");
    }

    /**
     * "expertTitleCode";   // 专家职称code
     *
     * @param ctx
     * @param value
     */
    public static void setExpertTitleCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, EXPERTTITLECODE, value);
    }

    public static String getExpertTitleCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, EXPERTTITLECODE, "");
    }

    /**
     * "expertTitleNum";   // 专家职称号
     *
     * @param ctx
     * @param value
     */
    public static void setExpertTitleNum(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, EXPERTTITLENUM, value);
    }

    public static String getExpertTitleNum(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, EXPERTTITLENUM, "");
    }

    /**
     * "expertTitleImage";   // 专家职称照片
     *
     * @param ctx
     * @param value
     */
    public static void setExpertTitleImage(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, EXPERTTITLEIMAGE, value);
    }

    public static String getExpertTitleImage(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, EXPERTTITLEIMAGE, "");
    }

    /**
     * "idCardNum";   // 身份证号
     *
     * @param ctx
     * @param value
     */
    public static void setIdCardNum(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, IDCARDNUM, value);
    }

    public static String getIdCardNum(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, IDCARDNUM, "");
    }

    /**
     * "idCardImage";   // 身份证照片
     *
     * @param ctx
     * @param value
     */
    public static void setIdCardImage(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, IDCARDIMAGE, value);
    }

    public static String getIdCardImage(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, IDCARDIMAGE, "");
    }

    /**
     * "isAudit";   // 第一次审核
     *
     * @param ctx
     * @param value isAudit 0 审核未通过  1 审核通过  2 待审核  3 已注册 未提交
     */
    public static void setIsAudit(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, ISAUDIT, value);
    }

    public static String getIsAudit(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, ISAUDIT, "");
    }

    /**
     * "isChangeAudit";   // 修改后审核
     *
     * @param ctx
     * @param value isChangeAudit 0 审核未通过  1 审核通过  2 待审核  3 未修改
     */
    public static void setIsChangeAudit(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, ISCHANGEAUDIT, value);
    }

    public static String getIsChangeAudit(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, ISCHANGEAUDIT, "");
    }


    public static void setOrganizationID(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, ORGANIZATION_ID, value);
    }

    public static String getOrganizationID(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, ORGANIZATION_ID, "");
    }

    public static void setOrganizationName(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, ORGANIZATION_NAME, value);
    }

    public static String getOrganizationName(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, ORGANIZATION_NAME, "");
    }

    public static void setOtherAddress(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, OTHERADDRESS, value);
    }

    public static String getOtherAddress(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, OTHERADDRESS, "");
    }

    public static void setBirthday(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_EXPERT_INFO, BIRTHDAY, value);
    }

    public static String getBirthday(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_EXPERT_INFO, BIRTHDAY, "");
    }

}
